<?php
require "../includes/db.php"; 
$mysqli = new MossCMS();
if ($_SESSION[$prefix.'_username'] == ""){  header("Location: ../login.php"); exit;}
if ($_SESSION[$prefix."_security"] < 1){header("location:../login.php?action=5"); exit;}


if ($_SERVER['REQUEST_METHOD'] == "POST") { 

	$name 		= $_POST['name'];
	$active		= $_POST['active'];
	$content	= $_POST['editor1'];
	$comments	= $_POST['comments'];

	$mysqli->pages_add($name, '',$active);
		$last_id = $mysqli->insert_id;
		
		//WRITE CONTENT TO FILE
		$file = $global_upload_dir."pages/".$last_id.".txt";
		$mysqli->pages_edit($last_id,$name,$file,$active);
			$handle = fopen($file, "w");
			fwrite($handle, $content);
			fclose($handle);
		$mysqli->admin_action($z_user, "Added a Custom Page $name ($last_id)");
header("Location:pages_list.php"); exit;
}//END POST 



$action = $_GET['action'];
$news_id = $_GET['id'];


?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="../includes/admin.css"/>
<title><?php echo $global_title;?></title>


<?php echo $ckeditor_global; ?>
</head>
<body>

<div id="wrap">
	<div id="page-header">
		<?php include('includes/header.php');?>

	</div>
	
	<div id="page-body">
		<div id="tabs">
			<?php $tab="main"; include('includes/header_tabs.php');?>
		</div>

		<div id="acp">
		<div class="panel">
			<span class="corners-top"><span></span></span>
				<div id="content">
				<div id="menu">
						
					<?php include('includes/menu_top.php');?>	
					<?php include('includes/menu_main.php');?>
					</div>
	
					<div id="main">
<a name="maincontent"></a>


<h1>Create Page </h1>
	
<form action="" method="post" enctype="multipart/form-data" name="form1">
    
        <fieldset><legend></legend>
		  
		<dl>
             <dt>Page Name:</dt>
             <dd><input type="text" name="name" id="name" autofocus required  value="" size="50" /></dd>
        </dl>

        <dl>
          <dt>Active:</dt>
          <dd>
            <select name="active" id="active" >
                <option value="1" <?php if($inarr["page_active"] == 't'){echo "selected='selected'";}?>>Yes</option>
				<option value="0" <?php if($inarr["page_active"] == 'f'){echo "selected='selected'";}?>>No</option>
              </select>
            </dd>
        </dl> 
        

			<textarea name="editor1" id="editor1" class="nicedit_textarea" style="height: 300px;"></textarea>
            
            
                       
<p class="submit-buttons"><input type="submit" class="button1" name="submit" id="submit" value="Submit" /></p>

        </fieldset>

    </form>
    
		</div><!-- main -->
	</div><!-- content -->
<span class="corners-bottom"><span></span></span>
</div><!-- panel -->
</div><!-- acp -->

	
	<div id="page-footer">
	<?php include('includes/footer.php');?>
				</div>
</div><!-- page-body -->
</div><!-- wrap -->

   <script type="text/javascript">
   
	CKEDITOR.replace( 'editor1', {toolbar : 'MyToolbar'} );
	
	CKEDITOR.config.width = '98%';
	CKEDITOR.config.height = '300';
	CKEDITOR.config.resize_maxWidth = '98%';
	CKEDITOR.config.toolbarStartupExpanded = 'true';
	
</script>


</body> 
</html>